/* ********************************************************************** */
/*                           Motor Speed measurement                      */
/*                                                                        */
/* Allow you to measure the speed of a brushless motor                    */
/* You need to connect the right pin (gate) of one of the transistors     */
/* of your ESC to ADC0 of your Arduino board.                             */
/* Also measure the voltage on the transistor gate                        */
/* You need to divide the voltage to comply with Arduino 0-5V.            */
/* Date : 16/04/2010                                                      */
/* Author : Loris Rion                                                    */
/* Version : 1.4                                                          */
/* ********************************************************************** */

// Sampling time constant
// It means accuracy constant in %
// With a sampling rate of 10 Hz
// and ADC clock at 250 KHz
// accuracy is around 0.1%
#define SAMPLING_TIME 100000 //in us
#define POLES 14 //number of poles of the motor

#define R_DIVISOR 11.16 //divisor at ADC input
#define VREF 4.96 //reference voltage

// ADC variables
int adc_old; //previous adc value
int adc_new; //current adc value
long count_rising = 0; //counter of rising edge
unsigned long freq; //motor frequency
unsigned long motor_speed; //motor speed
unsigned long adc_raw;
unsigned int adc_count;

// for timer
unsigned long tt;
unsigned long ttold;

void setup(){
  Serial.begin(38400);
  Analog_Init();
}

void loop(){
}
